package com.shrct.businessprocess.purchase.impl;

import com.shrct.businessprocess.budget.RCBudget;
import com.shrct.businessprocess.budget.impl.RCBudgetImpl;
import com.shrct.businessprocess.project.RCProjectMoney;
import com.shrct.businessprocess.project.RCRealMoney;
import com.shrct.businessprocess.purchase.RCPay;
import com.shrct.businessprocess.purchase.RCPayRequest;
import com.shrct.businessprocess.purchase.impl.RCPayRequestImpl;
import com.shrct.businessprocess.purchase.proxy.RCPayProxy;
import edu.fudan.mylang.pf.BaseModelObject;
import edu.fudan.mylang.pf.IObjectFactory;
import java.util.Date;
import javax.persistence.AssociationOverride;
import javax.persistence.AssociationOverrides;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.hibernate.annotations.DiscriminatorOptions;

@Entity
@DiscriminatorValue("RCPAY_TYPE")
@DiscriminatorOptions(force = true)
@DiscriminatorColumn(length = 64)
@Table(name = "rcpay")
public class RCPayImpl extends BaseModelObject implements RCPay {
  public RCPayImpl() {
    super();
  }
  
  public RCPayImpl(final RCBudget budget, final RCPayRequest payRequest) {
    super();
    this.budget = budget;;
    this.payRequest = payRequest;
  }
  
  @JoinColumn(name = "payRequest_id")
  @ManyToOne(targetEntity = RCPayRequestImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private RCPayRequest payRequest;
  
  public RCPayRequest getPayRequest() {
    return this.payRequest;
  }
  
  public RCPay setPayRequest(final RCPayRequest payRequest) {
    this.payRequest = payRequest;
    return this;			
    
  }
  
  @JoinColumn(name = "budget_id")
  @ManyToOne(targetEntity = RCBudgetImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private RCBudget budget;
  
  public RCBudget getBudget() {
    return this.budget;
  }
  
  public RCPay setBudget(final RCBudget budget) {
    this.budget = budget;
    return this;			
    
  }
  
  @Embedded
  @AttributeOverrides(value = { @AttributeOverride(name = "amount", column = @Column(name = "projectAmount_amount") ), @AttributeOverride(name = "workaround", column = @Column(name = "projectAmount_workaround") ) } )
  @AssociationOverrides(value = @AssociationOverride(name = "exchange", joinColumns = @JoinColumn(name = "projectAmount_exchange") ) )
  private RCProjectMoney projectAmount = com.shrct.businessprocess.project.RCProjectMoney.create();
  
  public RCProjectMoney getProjectAmount() {
    return this.projectAmount;
  }
  
  public RCPay setProjectAmount(final RCProjectMoney projectAmount) {
    this.projectAmount = projectAmount;
    return this;			
    
  }
  
  @Embedded
  @AttributeOverrides(value = { @AttributeOverride(name = "amount", column = @Column(name = "amount_amount") ), @AttributeOverride(name = "exchangeRate", column = @Column(name = "amount_exchangeRate") ), @AttributeOverride(name = "workaround", column = @Column(name = "amount_workaround") ) } )
  @AssociationOverrides(value = @AssociationOverride(name = "currencyType", joinColumns = @JoinColumn(name = "amount_currencyType") ) )
  private RCRealMoney amount = com.shrct.businessprocess.project.RCRealMoney.create();
  
  public RCRealMoney getAmount() {
    return this.amount;
  }
  
  public RCPay setAmount(final RCRealMoney amount) {
    this.amount = amount;
    return this;			
    
  }
  
  private Date payDate;
  
  public Date getPayDate() {
    return this.payDate;
  }
  
  public RCPay setPayDate(final Date payDate) {
    this.payDate = payDate;
    return this;			
    
  }
  
  public static RCPay create(final RCBudget budget, final RCPayRequest payRequest, final IObjectFactory objectFactory) {
    com.shrct.businessprocess.purchase.RCPay rCPay = new com.shrct.businessprocess.purchase.impl.RCPayImpl(
    	budget,payRequest
    );
    objectFactory.create(rCPay);
    return rCPay;			
    
  }
  
  public static RCPay createRCPayImpl(final RCBudget budget, final RCPayRequest payRequest, final IObjectFactory objectFactory, final Procedure1<RCPay> init) {
    com.shrct.businessprocess.purchase.RCPay rCPay = new com.shrct.businessprocess.purchase.impl.RCPayImpl(
    	budget,payRequest
    );
    objectFactory.create(rCPay);
    init.apply(rCPay);
    
    return rCPay;			
    
  }
  
  public RCPayProxy toProxy() {
    com.shrct.businessprocess.purchase.proxy.RCPayProxy proxy = new com.shrct.businessprocess.purchase.proxy.RCPayProxy();
    proxy.setId(this.getId());
    if(this instanceof edu.fudan.mylang.pf.INamedModelObject){
    	proxy.setName(((edu.fudan.mylang.pf.INamedModelObject)this).getEntityName());
    }
    return proxy;
    
  }
}
